var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/imp/cpts/components/MasterSlaveTable.tsx
var MasterSlaveTable_exports = {};
__export(MasterSlaveTable_exports, {
  default: () => MasterSlaveTable_default
});
module.exports = __toCommonJS(MasterSlaveTable_exports);
var import_react = require("react");
var import_functionalComponent = require("../../../../functionalComponent");
var import_util = require("../../../../util");
var import_query_panel = require("../../../query-panel");
var import_constants = require("../../constants");
var import_service = require("../../service");
var import_NoticeIconContent = __toESM(require("./NoticeIconContent"));
var MasterSlaveTable = (props) => {
  const { getRef, state, popupMode, flowCode, busData, dependentState, changeDependent, rowDisable, iconVisible } = props;
  const tableMainRequest = (0, import_react.useCallback)(
    (defaultParams) => {
      return (0, import_service.loadSourceData)({
        flowCode,
        busData,
        ...defaultParams,
        popupMode,
        sourceId: state == null ? void 0 : state.masterFormId
      });
    },
    [popupMode, state.masterFormId]
  );
  const tableRequest = (0, import_react.useCallback)(
    (defaultParams) => {
      if (!(dependentState == null ? void 0 : dependentState.length)) {
        return Promise.resolve({ total: 0, list: [] });
      }
      const sourceId = state.sourceId;
      const newsourceId = (sourceId == null ? void 0 : sourceId.indexOf("_")) ? import_util.iup.split(sourceId, "_")[1] : sourceId;
      return (0, import_service.loadSourceData)({
        flowCode,
        busData,
        ...defaultParams,
        popupMode,
        sourceId: newsourceId,
        masterId: dependentState.map((x) => x.id).join(",")
      });
    },
    [JSON.stringify(dependentState)]
  );
  const onSearch = (_, queryCondition) => {
    var _a, _b;
    (_b = (_a = getRef("tableMain")) == null ? void 0 : _a.current) == null ? void 0 : _b.getApi().setExtraParam({ queryCondition });
    changeDependent([]);
  };
  return /* @__PURE__ */ React.createElement(import_util.Layout, { direction: "column" }, state.masterQueryItems.length > 0 && /* @__PURE__ */ React.createElement(import_query_panel.QueryPanel, { items: state.masterQueryItems, onSearch }), /* @__PURE__ */ React.createElement(import_util.Layout.Slider, { size: 200 }, /* @__PURE__ */ React.createElement(
    import_functionalComponent.Table,
    {
      showRowNumber: true,
      columns: state.masterColumns,
      ref: getRef("tableMain"),
      autoLoad: true,
      request: tableMainRequest,
      key: state.sourceId,
      pagination: { hideOnSinglePage: false },
      onCheckedChange: (selectedRows) => {
        changeDependent(selectedRows);
      },
      rowSelection: {
        type: [import_constants.MasterSlaveSelectEnum.MULTIPLE].includes(state.allowMultiSelect) ? [import_functionalComponent.TableSelectionModel.MULTIPLE_INTERVAL, import_functionalComponent.TableSelectionModel.CHECKBOX] : import_functionalComponent.TableSelectionModel.ROW
      },
      onRow: (_, __, row) => {
        return [import_constants.MasterSlaveSelectEnum.RADIO, import_constants.MasterSlaveSelectEnum.ONLY_CHILD_MULTIPLE].includes(
          state.allowMultiSelect
        ) ? { onClick: () => changeDependent([row]) } : {};
      }
    }
  )), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(import_NoticeIconContent.default, { iconVisible }, /* @__PURE__ */ React.createElement(
    import_functionalComponent.Table,
    {
      showRowNumber: true,
      columns: state.columns,
      ref: getRef("table"),
      request: tableRequest,
      key: state.sourceId,
      pagination: { hideOnSinglePage: false },
      rowSelection: {
        type: [import_constants.MasterSlaveSelectEnum.MULTIPLE, import_constants.MasterSlaveSelectEnum.ONLY_CHILD_MULTIPLE].includes(
          state.allowMultiSelect
        ) ? [import_functionalComponent.TableSelectionModel.MULTIPLE_INTERVAL, import_functionalComponent.TableSelectionModel.CHECKBOX] : import_functionalComponent.TableSelectionModel.ROW,
        disabled: rowDisable
      }
    }
  ))));
};
var MasterSlaveTable_default = (0, import_react.memo)(MasterSlaveTable);
